package be.kuleuven.mume.paginas;

import be.kuleuven.mume.R;
import be.kuleuven.mume.framework.AgendaItem;
import be.kuleuven.mume.framework.Mobilenvi;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TextView;

public class AgendaTabBar extends TabActivity  implements OnClickListener{
	public static int ALL_ITEMS = 0;
	public static int DEADLINES = 1;
	
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
	    setContentView(R.layout.vaktab);
	    
	    if ( customTitleSupported ) {
            getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
	    }
	    
	    createTab();
	}
	
	private void createTab(){
		addTab("Alle", AgendaItem.TypeItem.Alles);
		addTab("Uurrooster", AgendaItem.TypeItem.Uurooster);
		addTab("Deadlines", AgendaItem.TypeItem.Deathline);
		addTab("Afspraken", AgendaItem.TypeItem.Afspraken);
		addTab("VrijeTijd", AgendaItem.TypeItem.VrijeTijd);
		
		
		for (int i = 0 ; i < getTabWidget().getChildCount() ; i++){
			View tab = getTabWidget().getChildAt(i);
			tab.setOnClickListener(this);
			tab.setTag(i);
			tab.getLayoutParams().height = Mobilenvi.tabHeight;
		}
		
        TextView myTitleText = (TextView) findViewById(R.id.myTitle);
        if ( myTitleText != null ) {
            myTitleText.setText(R.string.agenda);
        }
	}
	
	private void addTab(String title, AgendaItem.TypeItem filterId) {
	    TabHost tabHost = getTabHost();  // The activity TabHost
	    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
	    Intent intent;  // Reusable Intent for each tab

	    // Create an Intent to launch an Activity for the tab (to be reused)
	    intent = new Intent().setClass(this, AgendaPagina.class);
	    intent.putExtra(AgendaPagina.FILTER_ID, filterId);

	    // Initialize a TabSpec for each tab and add it to the TabHost
	    spec = tabHost.newTabSpec(title).setIndicator(title)
	                  .setContent(intent);
	    tabHost.addTab(spec);
	}

	public void onClick(View v) {
		getTabHost().setCurrentTab((Integer)v.getTag());
	}
}
